//
//  XCAttentionSearcherViewController.m
//  XCNewsApp
//
//  Created by FAITH on 16/12/9.
//  Copyright © 2016年 XC. All rights reserved.
//

#import "XCAttentionSearcherViewController.h"
#import "XCAttentionSearchContentController.h"
#import "XCNavigationController.h"
@interface XCAttentionSearcherViewController ()<UISearchBarDelegate,UIWebViewDelegate>
@property(nonatomic,weak) UIWebView *webView;

@property(nonatomic,strong) UISearchBar *searchBar;
@end

@implementation XCAttentionSearcherViewController

//懒加载
-(UISearchBar *)searchBar
{
    if (_searchBar==nil){
        UISearchBar *searchBar=[[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 44)];
        
        searchBar.placeholder=@"搜你关心的";
        
        searchBar.delegate=self;
        
        _searchBar=searchBar;

    }
    return _searchBar;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.titleView=self.searchBar;
    
    UIWebView *webView=[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
    
    //自动对页面进行缩放
    webView.scalesPageToFit=YES;
    
    webView.dataDetectorTypes=UIDataDetectorTypeAll;
    
    webView.delegate=self;
    
    NSString * content_url=[NSString stringWithFormat:@"http://lf.snssdk.com/concern/v1/guide/page/?iid=%@",(IID)];
    
    NSURLRequest *request= [NSURLRequest requestWithURL:[NSURL URLWithString:content_url]];
    
    [webView loadRequest:request];
    
    [self.view addSubview:webView];
    
    self.webView=webView;
    

}


-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    XCAttentionSearchContentController *searchContent=[[XCAttentionSearchContentController alloc] init];
    
    XCNavigationController *nav=[[XCNavigationController alloc] initWithRootViewController:searchContent];
    
    [self.navigationController presentViewController:nav animated:YES completion:nil];
    
    return YES;
}

-(void)webViewDidStartLoad:(UIWebView *)webView
{
    [SVProgressHUD showWithStatus:@"哥正在帮你加载中..."];
    
    [UIApplication sharedApplication].networkActivityIndicatorVisible=YES;
}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    [SVProgressHUD dismiss];
    
    [UIApplication sharedApplication].networkActivityIndicatorVisible=NO;
}

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    return YES;
}



@end
